<HEAD>
  <SCRIPT SRC="../ganja.js"></SCRIPT>
</HEAD>
<BODY><SCRIPT>
// Create a Clifford Algebra with 2,0,1 metric.
Algebra(2,0,1,()=>{

  // Upgrade to 2D PGA.
  var point      = (x,y)=>1e12-x*1e02+y*1e01,
      line       = (a,b,c)=>a*1e1+b*1e2+c*1e0,
      dist_pp    = (X,Y)=>(X&Y).Length,
      dist_pl    = (P,l)=>(P.Normalized^l.Normalized).e012,
      angle      = (x,y)=>Math.acos(x.Normalized<<y.Normalized),
      project_pl = (P,l)=>(l<<P)*l,
      project_lp = (P,l)=>(l<<P)*P,
      reject_lp  = (P,l)=>(l<<P);

  // Rotations can be specified through exponentiation (angle around point).
  var rotor = (point,angle)=>Math.cos(angle/2) + Math.sin(angle/2)*point.Normalized;
  
  // Translations can similarly be expressed through exponentiation.
  var translator = (line,distance)=>1+0.5*distance*(line.Normalized*1e012);
  
  // Define some points and lines.
  var A=point(0,0), B=point(0.5,-0.5), l=line(0,1,0), l2=line(1,0,0);
  
  // Translator along line l
  var tr = ()=>translator(l,0.5*Math.sin(performance.now()*0.001));
  
  // Rotating around origin, then apply translator.
  var rt = ()=>tr*rotor(1e12,performance.now()*0.001);
  
  // Graph it
  document.body.appendChild(this.graph([
    "Versors", ()=>[tr>>>A,rt>>>B], ()=>tr>>>A, "tr>>>A", ()=>rt>>>B, "rt>>>B",
  ],{grid:true, animate:true}));
});
</SCRIPT></BODY>